<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>新增专家</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script src="./js/jquery.min.js"></script>
    <script type="text/javascript" src="./lib/layui/layui.js"
            charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>

    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <div class="layui-form-item">
                <label for="professorName" class="layui-form-label"> <span
                        class="x-red">*</span>专家姓名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="professorName" name="professorName" lay-verify="professorName"
                           required="required" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="gender" class="layui-form-label">
                    性别
                </label>
                <div class="layui-input-inline" style="margin-top: 8px;">
                    <input type="checkbox" id="gender" name="gender" lay-skin="switch" lay-text="男|女" checked="checked"
                           lay-filter="gender" class="layui-input"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="birthday" class="layui-form-label">
                    出生年月
                </label>
                <div class="layui-input-inline">
                    <input id="birthday" name="birthday"
                           lay-verify="birthday" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="identityNumber" class="layui-form-label">
                    身份证号
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="identityNumber" name="identityNumber"
                           lay-verify="identityNumber" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="workStatus" class="layui-form-label">
                    工作状态
                </label>
                <div class="layui-input-inline">
                    <select name="workStatus" id="workStatus">

                    </select>

                </div>
            </div>
            <div class="layui-form-item">
                <label for="institution" class="layui-form-label">
                    毕业院校
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="institution" name="institution"
                           lay-verify="institution" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="education" class="layui-form-label">
                    学历
                </label>
                <div class="layui-input-inline">
                    <select name="education" id="education">

                    </select>

                </div>
            </div>
            <div class="layui-form-item">
                <label for="major" class="layui-form-label">
                    专业
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="major" name="major"
                           lay-verify="major" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="employCompany" class="layui-form-label">
                    工作单位
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="employCompany" name="employCompany"
                           lay-verify="employCompany" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="administrative" class="layui-form-label">
                    行政职务
                </label>
                <div class="layui-input-inline">
                    <select type="text" id="administrative" name="administrative"
                            lay-verify="administrative" autocomplete="off" class="layui-input">
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="technicalPost" class="layui-form-label">
                    行政职务
                </label>
                <div class="layui-input-inline">
                    <select type="text" id="technicalPost" name="technicalPost"
                            lay-verify="technicalPost" autocomplete="off" class="layui-input">
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="telephone" class="layui-form-label">
                    固定电话
                </label>
                <div class="layui-input-inline">
                    <input type="telephone" id="telephone" name="phone"
                           lay-verify="telephone" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="mobliePhone" class="layui-form-label">
                    手机号
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="mobliePhone" name="mobliePhone"
                           lay-verify="mobliePhone" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="address" class="layui-form-label">
                    所在地址
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="address" name="address" placeholder="可以通过下方的选择或者直接输入"
                           lay-verify="address" autocomplete="off" class="layui-input">
                </div>
                <!-- start-->
                <div class="layui-form-item x-city" id="end">
                    <!--<label class="layui-form-label">所在地址</label>-->
                    <div class="layui-input-inline">
                        <select name="province" id="province" lay-filter="province">
                            <option value="">请选择省</option>
                        </select>
                    </div>
                    <div class="layui-input-inline">
                        <select name="city" id="city" lay-filter="city">
                            <option value="">请选择市</option>
                        </select>
                    </div>
                    <div class="layui-input-inline">
                        <select name="area" id="area" lay-filter="area">
                            <option value="">请选择县/区</option>
                        </select>
                    </div>
                </div>

                <!-- end -->
            </div>
            <div class="layui-form-item">
                <label for="projectCategory" class="layui-form-label"> <span
                        class="x-red"></span>评审项目类型
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="projectCategory" name="projectCategory"
                           lay-verify="projectCategory" autocomplete="off"
                           class="layui-input" required="">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="workDate" class="layui-form-label"> <span
                        class="x-red"></span>专家工作的年限
                </label>
                <div class="layui-input-inline">
                    <input type="number" id="workDate" name="workDate"
                           lay-verify="workDate" autocomplete="off" class="layui-input" value="0" min="0" step="1"
                           required="">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="lostNum" class="layui-form-label"> <span
                        class="x-red"></span>专家连续未参加评标的次数
                </label>
                <div class="layui-input-inline">
                    <input type="number" id="lostNum" name="lostNum"
                           lay-verify="lostNum" autocomplete="off" class="layui-input" value="0" min="0" step="1"
                           required="">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="createBy" class="layui-form-label"> <span
                        class="x-red"></span>创建者
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="createBy" name="createBy"
                           lay-verify="createBy" autocomplete="off"
                           class="layui-input" required="">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="modifyBy" class="layui-form-label"> <span
                        class="x-red"></span>修改人
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="modifyBy" name="modifyBy"
                           lay-verify="modifyBy" autocomplete="off"
                           class="layui-input" required="" placeholder="第一次创建时，修改者同为创建者">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <label class="layui-form-label"></label>
                <button class="layui-btn" lay-filter="add" lay-submit="">增加</button>
            </div>
        </form>
    </div>
</div>

<script type="text/javascript" src="./js/xcity.js"></script>
<script>layui.use(['form', 'laydate', 'layer', 'jquery', 'code'],
    function () {
        var $ = layui.jquery;
        form = layui.form;
        var layer = layui.layer;
        var laydate = layui.laydate;

        //
        //传默认值
        $('#end').xcity('安徽', '合肥市', '包河区');

        //
        laydate.render({
            elem: '#birthday' //指定元素
            , trigger: 'click'
        });
        var $role = $("#workStatus");
        $.get("js/param.json", function (data) {
            $.each(data.workStatus, function (i, d) {
                $role.append(new Option(d, d));
            });
            form.render();//重绘表单
        });
        var $education = $("#education");
        $.get("js/param.json", function (data) {
            $.each(data.education, function (i, d) {
                $education.append(new Option(d, d));
            });
            form.render();//重绘表单
        });
        var $administrative = $("#administrative");
        $.get("js/param.json", function (data) {
            $.each(data.administrative, function (i, d) {
                $administrative.append(new Option(d, d));
            });
            form.render();//重绘表单
        });
        var $technicalPost = $("#technicalPost");
        $.get("js/param.json", function (data) {
            $.each(data.technicalPost, function (i, d) {
                $technicalPost.append(new Option(d, d));
            });
            form.render();//重绘表单
        });
        //
        // form.on('select(province)',function (data) {
        //     initAddr();
        //     return true;
        // });

        //$("#city").click(initAddr);
        //$("#city").click(initAddr);
        // form.on('select(city)',function (data) {
        //     initAddr();
        // });
        // form.on('select(area)',function (data) {
        //     initAddr();
        // });
        function initAddr() {

            var p = $("#province").val();
            var c = $("#city").val();
            var area = $("#area").val();
            $("#address").val(p + " " + c + " " + area);
            form.render();
        }

        //自定义验证规则
        form.verify({

            professorName: function (value) {
                if (value.length < 2 || value.length > 12) {
                    return '用户名必须是2-12个字符';
                }
            },
            mobliePhone: [/^1\d{10}$/, '手机号必须为11位数字'],
            // identityNumber : [ /\d{17}(\d|X)$/, '身份证必须是18位' ]

        });

        //监听提交
        form.on('submit(add)',
            function (data) {
                if (data.field.gender == "on") {
                    data.field.gender = "男";
                } else {
                    data.field.gender = "女";
                }
                //initAddr();
                var p = $("#province").val();
                var c = $("#city").val();
                var area = $("#area").val();
                data.field.address = p + " " + c + " " + area;
                alert(JSON.stringify(data.field));
                //发异步，把数据提交给
                $.post("professorAdd", data.field, function (r) {
                    if (r > 0) {
                        parent.layer.alert("增加成功", {
                            icon: 6
                        }, function (index, item) {
                            xadmin.close();
                            // 可以对父窗口进行刷新
                            xadmin.father_reload();
                        });
                    } else {
                        parent.layer.alert("增加失败，请核对", {
                            icon: 1
                        });
                    }
                });
                return false;
            });
    });
</script>

</body>

</html>    